use strict;
use warnings;

package Tie::ModHash;
require Tie::Hash;
our @ISA = qw/Tie::StdHash/;
use Carp qw/croak/;

my $STRICT   = " STRICT";
my $MODIFIED = " MODIFIED";

sub STORE {
	my ($self, $key, $value) = @_;
	$self->{$MODIFIED} = 1;
	if (exists $self->{$STRICT} and not exists $self->{$key}) {
		croak "key '$key' does not exist";
	}
	$self->{$key} = $value;
}
sub FETCH {
	my ($self, $key) = @_;
	if (exists $self->{$STRICT} and not exists $self->{$key}) {
		croak "key '$key' does not exist";
	}
	$self->{$key};
}
sub modified {
	my ($self) = @_;
	exists $self->{$MODIFIED}? 1: 0;
}
sub strict {
	my ($self) = @_;
	$self->{$STRICT} = 1;
}
sub no_strict {
	my ($self) = @_;
	delete $self->{$STRICT};
}
sub clear {
	my ($self) = @_;
	delete $self->{$MODIFIED};
}

1;
